package com.pozu.new_retail.service.impl;

import java.util.HashMap;
import java.util.List;

import com.pozu.new_retail.dao.mapper.MessageMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pozu.new_retail.dao.model.Message;
import com.pozu.new_retail.dao.vo.CommentMessageVo;
import com.pozu.new_retail.dao.vo.MessageVo;
import com.pozu.new_retail.dao.vo.OrderMessageVo;
import com.pozu.new_retail.dao.vo.UgcMessageVo;
import com.pozu.new_retail.dao.vo.UpvoteMessageVo;
import com.pozu.new_retail.service.MessageService;

@Service("messageService")
public class MessageServiceImpl implements MessageService {

	@Autowired
	private MessageMapper messageMapper;
	
	@Override
	public int queryCountByMap(HashMap<String, Object> hashMap) {
		return messageMapper.queryCountByMap(hashMap);
	}

	@Override
	public int saveMessage(Message message) {
		
		message.setCreatedTime(System.currentTimeMillis());
		
		return messageMapper.insertMessage(message);
	}

	@Override
	public int updateMessage(HashMap<String, Object> hashMap) {
		return messageMapper.updateMessage(hashMap);
	}

	@Override
	public List<UpvoteMessageVo> queryUpvoteMessageByMap(HashMap<String, Object> hashMap) {
		return messageMapper.queryUpvoteMessageByMap(hashMap);
	}

	@Override
	public List<CommentMessageVo> queryCommentMessageByMap(HashMap<String, Object> hashMap) {
		return messageMapper.queryCommentMessageByMap(hashMap);
	}

	@Override
	public List<UgcMessageVo> queryUgcMessageByMap(HashMap<String, Object> hashMap) {
		return messageMapper.queryUgcMessageByMap(hashMap);
	}

	@Override
	public List<OrderMessageVo> queryOrderMessageByMap(HashMap<String, Object> hashMap) {
		return messageMapper.queryOrderMessageByMap(hashMap);
	}

	@Override
	public MessageVo queryMessageInfo(long userId,int appId) {
		
		MessageVo messageVo = new MessageVo();
		
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("userId", userId);
		hashMap.put("type", 0);
		hashMap.put("appId", appId);
		
		messageVo.setUpvoteMessageNumber(messageMapper.queryCountByMap(hashMap));
		messageVo.setUpvoteMessageVo(messageMapper.queryLastUpvoteMessage(hashMap));
		
		hashMap.put("type", 1);
		
		messageVo.setCommentMessageNumber(messageMapper.queryCountByMap(hashMap));
		messageVo.setCommentMessageVo(messageMapper.queryLastCommentMessage(hashMap));
		
		
		hashMap.put("type", 2);
		
		messageVo.setUgcMessageNumber(messageMapper.queryCountByMap(hashMap));
		messageVo.setUgcMessageVo(messageMapper.queryLastUgcMessage(hashMap));
		
		hashMap.put("type", 3);
		
		messageVo.setOrderMessageNumber(messageMapper.queryCountByMap(hashMap));
		messageVo.setOrderMessageVo(messageMapper.queryLastOrderMessage(hashMap));
		
		
		return messageVo;
	}

}
